import java.util.Stack;

class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String x = tokens[i];
            if(isOpertation(x) == false){

                stack.push(Integer.parseInt(x));

            }else {
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch(x){
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                        break;
                }
            }
        }
        return stack.pop();
    }

    private boolean isOpertation(String x)
    {
        return ( "+".equals(x) ||  "-".equals(x) || "*".equals(x) ||  "/".equals(x) );

    }
}



